package com.tanhua.server.controller;

import com.tanhua.domain.vo.CountsVo;
import com.tanhua.domain.vo.FriendVo;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.domain.vo.UserInfoVo;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/users")
public class UserInfoController {
    @Autowired
    private UserService userService;

    @GetMapping
    public ResponseEntity getLoginUserInfo(@RequestHeader("Authorization") String token, String userId, String huanxiId) {
        UserInfoVo userInfoVo = userService.getLoginUserInfo(token);
        return ResponseEntity.ok(userInfoVo);
    }

    @PutMapping
    public ResponseEntity updateLoginUserInfo(@RequestHeader("Authorization") String tocken, @RequestBody UserInfoVo userInfoVo) {
        userService.updateLogeinUserInfo(tocken, userInfoVo);
        return ResponseEntity.ok(null);
    }

    @PostMapping("/header")
    public ResponseEntity updateLoginUserAvatar(MultipartFile headPhoto, @RequestHeader("Authorization") String tocken) {
        userService.deleteLoginUserAvatar(tocken);
        userService.uploadAvatar(headPhoto, tocken);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/counts")
    public ResponseEntity<CountsVo> counts() {
        CountsVo countsVo = userService.counts();
        return ResponseEntity.ok(countsVo);
    }

    @GetMapping("/friends/{type}")
    public ResponseEntity queryUserLikeList(@PathVariable int type, @RequestParam(value = "page", defaultValue = "1") Long page,
                                            @RequestParam(value = "pagesize", defaultValue = "10") long pagesize, String nickname) {
        PageResult<FriendVo> pageResult = userService.queryUserLikeList(type, page, pagesize, nickname);
        return ResponseEntity.ok(pageResult);
    }

    @PostMapping("/fans/{likeId}")
    public ResponseEntity LikeFences(@PathVariable Long likeId){
        userService.likeFences(likeId);
        return ResponseEntity.ok(null);
    }
}
